// import Navigo from 'navigo'
// import request from 'browser-request'
// import { bb } from 'billboard.js'
(() => {
  const ysums = {
      "1803":62564,   "1804":153566,  "1805":333009,  "1806":402385,
      "1807":330189,  "1808":356270,  "1809":425329,  "1810":108614,
      "1811":348244,  "1812":381222,  "1813":161795,  "1814":108473,
      "1815":305119,  "1817":427729,  "1818":198569,  "1819":712493,
      "1820":689939,  "1821":463673,  "1822":537909,  "1823":445485,
      "1824":455693,  "1825":447602,  "1826":486482,  "1827":373460,
      "1828":532269,  "1830":874749,  "1831":1470204, "1832":1190538,
      "1833":1181035, "1834":1032310, "1835":1054982, "1836":1022833,
      "1837":935591,  "1838":839888,  "1839":1129887, "1840":818502,
      "1841":864783,  "1842":1280028, "1843":1279540, "1844":529506,
      "1845":1345670, "1846":1332471, "1847":1470461, "1848":1036179,
      "1849":1092956, "1850":1060357, "1851":695420,  "1852":1215679,
      "1853":1223364, "1854":1574921, "1855":1246761, "1856":1202209,
      "1857":1398635, "1858":1270616, "1859":763606,  "1860":1377844,
      "1861":1310968, "1862":936073,  "1863":1186806, "1864":1023442,
      "1865":994230,  "1866":984449,  "1867":1535069, "1868":979254,
      "1869":1435839, "1870":1493402, "1871":1525131, "1872":1047035,
      "1873":1150867, "1874":770763,  "1875":1320932, "1876":1423104,
      "1877":1206528, "1878":1631899, "1879":1229900, "1880":1231870,
      "1881":1875252, "1882":1377694, "1883":2417655, "1884":1724323,
      "1885":1138262, "1886":1981644, "1887":2955797, "1888":2719001,
      "1889":1829895, "1890":1996446, "1891":472110,  "1892":1141106,
      "1893":1165521, "1894":1149626, "1895":1498549, "1896":1719063,
      "1897":1461291, "1898":1561329, "1899":1342773, "1900":1935998,
      "1901":1321952, "1902":2705084, "1903":994191,  "1904":1195586,
      "1905":1087716, "1906":1766904, "1907":1496225, "1908":1896247,
      "null":27555
    }
  const data_86 = [
    0,          126,            8,          5,
    14,         4,              43,         0,
    22,         33,             20,         0,
    94,         52,             222,        90,
    72,         15,             150,        18,
    65,         127,            41,         90,
    42,         52,             367,        212,
    1080,       184,            159,        351,
    247,        297,            328,        48,
    95,         541,            152,        125,
    227,        362,            219,        263,
    82,         300,            96,         399,
    210,        287,            385,        149,
    174,        195,            170,        359,
    431,        188,            705,        406,
    319,        587,            561,        183,
    646,        268,            977,        303,
    182,        178,            769,        497,
    472,        560,            372,        1717,
    3618,       5570,           3480,       2835,
    1483,       2863,           18255,      19660,
    19672,      21626,          2398,       1017,
    2063,       2097,           938,        1751,
    828,        1713,           1559,       1175,
    1523,       4688,           700,        1157,
    1756,       1363,           880,        2325,
  ]

  const data_415 = [
    3,      85,     17,     24,
    58,     11,     6,      2,
    39,     34,     3,      37,
    217,    44,     14,     35,
    42,     14,     26,     44,
    45,     52,     20,     10,
    84,     56,     85,     121,
    90,     127,    93,     104,
    46,     15,     180,    71,
    132,    205,    26,     60,
    208,    112,    109,    240,
    468,    634,    51,     40,
    220,    278,    213,    434,
    180,    443,    108,    248,
    433,    135,    117,    318,
    126,    82,     174,    131,
    232,    677,    234,    173,
    152,    125,    231,    308,
    199,    420,    180,    256,
    368,    827,    788,    1137,
    433,    953,    2163,   3895,
    3387,   2507,   230,    1238,
    1525,   2596,   1541,   2990,
    1388,   1353,   772,    1771,
    2281,   5095,   1706,   8630,
    12929,  21635,  19911,  19035,
  ]

  const data_461 = [
    2,      181,    0,      1,
    72,     8,      12,     1,
    1044,   202,    21,     77,
    87,     23,     18,     82,
    34,     97,     279,    118,
    47,     70,     98,     67,
    72,     601,    1082,   382,
    855,    983,    521,    1074,
    413,    1238,   282,    345,
    663,    228,    323,    200,
    247,    786,    2513,   610,
    1738,   1239,   208,    449,
    1621,   177,    453,    437,
    117,    329,    79,     169,
    536,    219,    512,    321,
    227,    259,    896,    403,
    2273,   2164,   671,    270,
    396,    90,     1169,   1196,
    1740,   1476,   1884,   8338,
    25394,  30900,  7478,   3004,
    2366,   24367,  62294,  27073,
    11692,  13506,  2579,   3956,
    5096,   6959,   6153,   11906,
    3721,   3295,   488,    6257,
    1290,   5045,   5895,   3575,
    1963,   2671,   5774,   3185,
  ]

  function loadchart(id) {
    const bindto = `#chart-${id}`
    const data =  {
      "x": "x-axis",
      "columns": [],
      "type": "area-spline"
    }
    return bb.generate({
      data, bindto, "point": { "show": true, "r" : 2 },
    })
  }

  function makechart(ysums) {

    const years = Object
      .keys(ysums)
      .map(x => parseInt(x))
      .sort()
    const ymap = (c, i) => 10000 * c / ysums[years[i]]
    const x = ['x-axis', ...years]
    const y_86  = [`per 10,000 words`,...data_86.map(ymap)]
    const y_415 = [`per 10,000 words`,...data_415.map(ymap)]
    const y_461 = [`per 10,000 words`,...data_461.map(ymap)]

    
    loadchart( 86).load({ columns : [x, y_86] })
    loadchart(415).load({ columns : [x, y_415] })
    loadchart(461).load({ columns : [x, y_461] })
  }

  makechart(ysums)
  console.log(bb)

})()